/**
 * Copyright (c) 2019, ShangHai YTO Co., Ltd.
 * All right reserved.
 *
 * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF YTO
 * CO., LTD.  THE CONTENTS OF THIS FILE MAY NOT BE DISCLOSED
 * TO THIRD PARTIES, COPIED OR DUPLICATED IN ANY FORM, IN WHOLE OR IN PART,
 * WITHOUT THE PRIOR WRITTEN PERMISSION OF YTO
 * CO., LTD.
 */
package org.sc.xl.easyexcel;

import com.alibaba.excel.write.handler.SheetWriteHandler;
import com.alibaba.excel.write.handler.context.SheetWriteHandlerContext;
import org.apache.poi.ss.usermodel.PrintSetup;
import org.apache.poi.ss.usermodel.Sheet;

/**
 * @description: TODO 请在此添加描述
 * @reason: TODO ADD REASON(可选)
 * @author FXL
 *
 * @date 2024/10/24 9:32 
 * @since JDK 1.8
 */
public class CustomSheetStyleHandler implements SheetWriteHandler {


    @Override
    public void beforeSheetCreate(SheetWriteHandlerContext context) {

    }

    @Override
    public void afterSheetCreate(SheetWriteHandlerContext context) {

        Sheet sheet = context.getWriteSheetHolder().getSheet();
        //设置将所有列调整为一页
        sheet.setFitToPage(true);
        //设置打印内容水平居中显示
        sheet.setHorizontallyCenter(true);
        //设置打印页面边距
        sheet.setMargin(Sheet.TopMargin, 0);
        sheet.setMargin(Sheet.BottomMargin, 0);
        sheet.setMargin(Sheet.LeftMargin, 0);
        sheet.setMargin(Sheet.RightMargin, 0);
        //打印设置对象
        PrintSetup print = sheet.getPrintSetup();
        //并缩减打印输出只有一页宽
        print.setFitHeight((short)0);
        print.setFitWidth((short) 1);
        //设置A4纸打印
        print.setPaperSize(PrintSetup.A4_PAPERSIZE);
    }
}